package com.zjitc.book.controller;

import com.zjitc.book.entity.Book;
import com.zjitc.book.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
public class BookController {
    @Autowired
    private BookService bookService;

    @GetMapping("/api/books")
    public List<Book> getBooks(){
        return bookService.getBooks();
    }

    @GetMapping("/api/books/{id}")
    public Book getBookById(@PathVariable Long id){
        return bookService.getBookById(id);
    }

    @GetMapping("/api/bookByCon")
    public List<Book> searchBooksByCon(Book book){
        return bookService.searchBooksByCon(book);
    }
    @PutMapping("/api/updateBook")
    public void UpdateBook(@RequestBody Book book){
        bookService.UpdateBook(book);
    }
    @DeleteMapping("/api/deleteById/{id}")
    public void deleteBookById(@PathVariable int id){
        bookService.deleteBookById(id);
    }

    @PostMapping("/api/addBook")
    public void addBook(@RequestBody Book book) {
        bookService.addBook(book);
    }

}